package cate.game.play.skill.passive.hero;

import cate.common.table.d.GDSkill;
import cate.common.util.XT;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.AppendMove;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.skill.Skill;
import cate.game.play.skill.effect.SkillEffect;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 攻击生命值低于40%的目标有60%概率发动【莲华伤】/n无冷却时间
 */
public class 莲华伊动PH extends PassiveHandler {

	private int 血量;

	private int 概率;

	private int 追加技能;

	//血量=4000&概率=6000&追加技能=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		血量 = args.getInt("血量", 0);
		概率 = args.getInt("概率", 0);
		追加技能 = args.getInt("追加技能", 0);
	}

	@Override
	public void parseExt(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		概率 += args.getInt("概率", 0);
	}

	private boolean append;

	@Override
	public void afterSelectTargets(SkillActionCtx action, SkillEffect effect) {
		if (append) {
			return;
		}
		if (action.getMove().isAppend()) {
			return;
		}
		if (!action.getSkill().cfg.isEffectType(GDSkill.EffectType.伤害)) {
			return;
		}
		for (Fighter target : action.getTargets()) {
			if (target.getTeam() != skill.owner.getTeam() && target.attr.total().hpCurRate() <= 血量 && XT.chance(概率)) {
				append = true;
				break;
			}
		}
	}

	@Override
	public void onOwnerMoveDone(MoveCtx move, TimeActionCtx action) {
		if (!append) {
			return;
		}
		append = false;
		Skill appendSkill = move.getCfg().skill.buildById(skill.owner, 追加技能);
		if (appendSkill == null) {
			return;
		}
		move.getTurn().addAppend(new AppendMove(skill.owner, appendSkill));
	}
}
